﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Simhopp.Model;

namespace Simhopp.GUI
{
    public partial class frmAddCompetition : Form, InterfaceAddCompetitionView
    {
        //public static bool databaseConnection;
        public event DelegateAddCompetition EventAddCompetition = null;
        public Competition PropCompetition { get; set; }    
        public frmAddCompetition()
        {
            InitializeComponent();
            cmbAgeClass.Items.AddRange(Enum.GetNames(typeof(Simhopp.Model.AgeClass)));
            cmbCompetitionType.Items.AddRange(Enum.GetNames(typeof(Simhopp.Model.CompetitionType)));
            cmbHeight.Items.AddRange(Enum.GetNames(typeof(Simhopp.Model.Height)));
            cmbNationality.Items.AddRange(Enum.GetNames(typeof(Simhopp.Model.Countries)));
        }

        private bool ReadInput()
        {
            if (InputUtility.ValidateString(txtLocation.Text) && InputUtility.ValidateString(txtName.Text))
            {
                return true;
            }
            else
                return false;
        }

        private void btnReturn_Click(object sender, EventArgs e)
        {
            this.Hide();
        }

        private void btnAdd_Click(object sender, EventArgs e)
        {
            char gender = ' ';

            if (rdoFemale.Checked == true)
            {
                gender = 'F';
            }
            else if (rdoMale.Checked == true)
            {
                gender = 'M';
            }

            if(EventAddCompetition != null)
            {
                // Saknas i konstruktorn: Datum, JudgingJudges, RoundsinCompetition och GenderGroupBox
                EventAddCompetition(new Competition(txtName.Text, 
                    (CompetitionType)Enum.Parse(typeof(CompetitionType), cmbCompetitionType.SelectedItem.ToString()), 
                    txtLocation.Text,
                    dateTimePicker1.Value.Date,
                    (Height)Enum.Parse(typeof(Height), cmbHeight.SelectedItem.ToString()), 
                    (AgeClass)Enum.Parse(typeof(AgeClass), cmbAgeClass.SelectedItem.ToString()),
                    gender, 5, 0));
                //EventAddCompetition(new Competition(1, "VM-kval", CompetitionType.International, "Sverige", new DateTime(2014, 2, 17), 1, 'B', 'M', 5, 3));
                this.Close();
            }

            MessageBox.Show("Competition added to database.");
        }

        private void frmAddCompetition_Load(object sender, EventArgs e)
        {
            if (frmLogin.databaseConnection == true)
                tsslDataConnect.Text = "Connected";
            else
                tsslDataConnect.Text = "Not Connected";
        }
    }
}
